{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "05c49dc5",
   "metadata": {},
   "source": [
    "----\n",
    "* 2023-11-6\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da66aecb",
   "metadata": {},
   "source": [
    "## 购物车程序项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e104a15d",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character '，' (U+FF0C) (2887045550.py, line 16)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[11], line 16\u001b[1;36m\u001b[0m\n\u001b[1;33m    扣钱，加商品进购物车(append)\u001b[0m\n\u001b[1;37m      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character '，' (U+FF0C)\n"
     ]
    }
   ],
   "source": [
    "#\n",
    "Alipay = input(\"请输入支付宝余额:\")\n",
    "商品列表 = [\n",
    "    \"内容\"\n",
    "]\n",
    "\n",
    "print(商品列表)\n",
    "购物车列表 = [\n",
    "    \n",
    "    \n",
    "]\n",
    "\n",
    "# 3.\n",
    "users_choese = input()\n",
    "if 余额 > 商品价格:\n",
    "    扣钱，加商品进购物车(append)\n",
    "else\n",
    "    print(...)\n",
    "    \n",
    "    \n",
    "break 退出循环，打印购物车\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "95628fd2",
   "metadata": {},
   "source": [
    "----\n",
    "\n",
    "> 购物车程序项目：\n",
    "> 1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    ">> A. 列表数据（第一种：自己创建的；第二种：空列表，后面补充数据）\n",
    "> 2. 让用户输入商品编号进行商品的购买。\n",
    ">> 1. <font style=\"color:red\">用户输入 input的结果必然是字符串 ste</font>\n",
    "> 3. 用户选择商品后，检查用户的余额是否够，若狗则直接扣款，不够则提醒用户。\n",
    "> 4. 用户可以随时退出购买，退出时打印用户已购买的商品和支付宝余额。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1f79db49",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (483159223.py, line 35)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[1], line 35\u001b[1;36m\u001b[0m\n\u001b[1;33m    elif 用户选择 == \"quit\":\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 1 创建列表\n",
    "alipay = int(input(\"请输入余额：\")) # 用户输入\n",
    "\n",
    "商品列表 = [\n",
    "    [\"iphone15\",8999],\n",
    "    [\"mate60 pro\",6999],\n",
    "    [\"桃桃奶昔\",7],\n",
    "    [\"ad钙奶\",8],\n",
    "    [\"安格斯牛肉堡\",50]\n",
    "]\n",
    "shopping_car = []\n",
    "\n",
    "# print(商品列表)\n",
    "\n",
    "# 3 循环执行\n",
    "while True:\n",
    "    print(\"--------小黄商铺(注：输入 quit 直接退出购买)--------\")\n",
    "    for i in 商品列表:\n",
    "        print(\"商品编号：%s ，商品名称: %s, 价格为：%s元\"%(商品列表.index(i),i[0],i[1]))\n",
    "\n",
    "    # 2 用户选商品\n",
    "    用户选择 = int(input(\"用户选择的商品编号:\"))\n",
    "    # 1. 如果输入 商品编号\n",
    "    if 用户选择.isdigit():\n",
    "        用户选择 = int(用户选择)\n",
    "    # 增加进购物车，扣钱？\n",
    "    if alipay > 商品列表[用户选择][1]:\n",
    "        # 1.钱够！扣钱，加入购物车\n",
    "        alipay = alipay - 商品列表[用户选择][1]\n",
    "        shopping_car.append(商品列表[用户选择])\n",
    "        print(\"您的余额为：%s 元\"%(alipay))\n",
    "    else:\n",
    "        print(\"就 %s 元，还想买 %s ಠ_ಠ!\"%(alipay,商品列表[用户选择][0]))\n",
    "    # 2. 如果输入字段 \"quit\" 则退出\n",
    "    elif 用户选择 == \"quit\":\n",
    "        print(\"感谢光顾小店，欢迎下次光临~\")\n",
    "        break\n",
    "        \n",
    "    # 3. 请输入正确的商品编号或者退出\n",
    "    else:\n",
    "        print(\"请输入正确的商品编号 或 输入'quit' 推出小店~\")\n",
    "        \n",
    "print(\"购物车：\",shopping_car)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4b8589a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 循环列表：可以遍历列表中的每一个元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "bbf92e30",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['iphone15', 8999]\n",
      "['mate60 pro', 6999]\n",
      "['桃桃奶昔', 7]\n",
      "['ad钙奶', 8]\n",
      "['安格斯牛肉堡', 50]\n"
     ]
    }
   ],
   "source": [
    "for item in 商品列表:\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d0f83acf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
